package functions;

public class Exp extends Term {
	private Function function;

	public Exp(double coff, double exp, Function func)
	{
		this.function = func;
		this.coff = coff;
		this.expon = exp;
	}

	@Override
	public double eval(double x)
	{
		return Math.pow(coff * Math.exp(function.eval(x)), expon);
	}

	@Override
	public FunctionIF diff()
	{
		if (expon == 0)
			return new PolynTerm(1, 0);

		/* Example sin(x^2)^3 */
		Exp diff = (Exp) clone(); // The differentiation of "E"

		FunctionIF d_fx = function.diff();
		return returnDerivative(diff, d_fx);
	}

	@Override
	protected Object clone()
	{
		return new Exp(coff, expon, (Function) function.clone());
	}

	@Override
	public String toString()
	{
		if (expon == 1)
			return coff + "*exp(" + function.toString() + ")";
		else
			return coff + "*exp(" + function.toString() + ")^" + expon;

	}

}
